package thread.processing.performance;

import java.util.concurrent.TimeUnit;

public class WithThread {
	static int counter = 0;
	
	public static void main(String[] args) throws InterruptedException {
		
		Runnable runnable = new Runnable() {
			@Override
			public void run() {
				try {
					Thread.sleep(1000);
					counter++;
				} catch (InterruptedException ex) {
					ex.printStackTrace();
				}
			}
		};
		
		
		long startTime = System.nanoTime();
		
		// start 10 threads
		Thread[] threads = new Thread[10];
		for(Thread t: threads){
			t = new Thread(runnable);
			t.start();
			t.join();
		}
		
		long elapsedTime = System.nanoTime() - startTime;
		long seconds = TimeUnit.SECONDS.convert(elapsedTime,
				TimeUnit.NANOSECONDS);
		System.out.println("Time taken : " + seconds + " Seconds");
		System.out.println("Completed Tries : " + counter);
		
	}
}
